<?php
defined( '_VALID_MOS' ) or die('<script>window.location.href="http://www.kinifurniture.com";</script>');
$adm_functions->is_admin_login();
$adm_menu='
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td class="menudottedline" width="40%">
			<div class="pathway"><img src="assets/admin/'.$SITE_LOGO_ADMIN.'"/></div>	</td>
		<td class="menudottedline" align="right">
			<table cellpadding="0" cellspacing="0" border="0" id="toolbar">
				<tr valign="middle" align="center">
					<td>&nbsp;</td>
					<td>
					<a class="toolbar" href="javascript:kliksubmit();">
						<img src="show_files/save.png"  alt="Save" name="save" title="Save" align="middle" border="0" />				<br />Save</a>
					</td>
					<td>&nbsp;</td>
					<td>
						<a class="toolbar" href="admin.php?show=user_manager">
						<img src="show_files/cancel.png"  alt="Cancel" name="cancel" title="Cancel" align="middle" border="0" />				<br />Cancel</a>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<br />
';
if ($msg=='1')	$error_message='Success Edit User Detail';

if ($id)
{
	$qryedit="select * from anggota where user_id=$id";
	$selectedit=$dbh->query($qryedit);

	while($sqlRowedit=mysql_fetch_object($selectedit))
	{
		$val_username=$sqlRowedit->username; 
		$val_password=$sqlRowedit->password;
		$val_password2=$sqlRowedit->password;
		if ($sqlRowedit->active=='Y') 
		{
			$val_select1='selected';
			$val_select2='';
		}
			else 
		{
				$val_select1='';
				$val_select2='selected';
		}
		if ($sqlRowedit->suspend=='Y') 
		{
			$val_select3='selected'; 
			$val_select4=''; 
		}
			else 
		{
			$val_select3=''; 
			$val_select4='selected'; 
		}
		$val_name=$sqlRowedit->nama;
		$val_tav=$sqlRowedit->tav_number;
		$val_company=$sqlRowedit->perus;
		$val_address=$sqlRowedit->alamat1;
		$val_zip=$sqlRowedit->zipcode;
		$val_city=$sqlRowedit->kota;
		$val_country=$sqlRowedit->negara;
		$val_email=$sqlRowedit->email;
		$val_telp=$sqlRowedit->telp;
		$val_fax=$sqlRowedit->fax;
		$val_userid=$id;
		$section='Edit User';
	}
}
if($inp_username)
{
	$qry="select * from anggota where username='$inp_username' and user_id!='$inp_userid'";
	$TOTAL_RECORDSET=$dbh->num_rows($dbh->query($qry));
	$qry1="select * from anggota where email='$inp_email' and user_id!='$inp_userid'";
	$TOTAL_RECORDSET1=$dbh->num_rows($dbh->query($qry1));
	if ($TOTAL_RECORDSET>0) $error_message='Username already exist ';
	if ($TOTAL_RECORDSET1>0) $error_message='Email already exist';
	if ($TOTAL_RECORDSET>0 and $TOTAL_RECORDSET1>0) $error_message='Username and Email already exist';
	if ($TOTAL_RECORDSET>0 || $TOTAL_RECORDSET1>0) 
	{
		$val_username=$inp_username; 
		$val_password=$inp_password;
		$val_password2=$inp_password;
		if ($inp_active=='Y') 
		{
			$val_select1='selected';
			$val_select2='';
		}
			else 
		{
				$val_select1='';
				$val_select2='selected';
		}
		if ($inp_suspend=='Y') 
		{
			$val_select3='selected'; 
			$val_select4=''; 
		}
			else 
		{
			$val_select3=''; 
			$val_select4='selected'; 
		}
//		$val_select2='';
//		$val_select3='';
//		$val_select4='selected';
		$val_name=$inp_name;
		$val_tav=$inp_tav;
		$val_company=$inp_company;
		$val_address=$inp_address;
		$val_zip=$inp_zip;
		$val_city=$inp_city;
		$val_country=$inp_country;
		$val_email=$inp_email;
		$val_telp=$inp_telp;
		$val_fax=$inp_fax;
		$section='Edit User';
	} else 
	{
	$dbh->query("update anggota set 
	username='$inp_username', 
	password='$inp_password',
	nama='$inp_name',
	active='$inp_active',
	suspend='$inp_suspend',
	tav_number='$inp_tav',
	perus='$inp_company',
	alamat1='$inp_address',
	zipcode='$inp_zip',
	kota='$inp_city',
	negara='$inp_country',
	email='$inp_email',
	telp='$inp_telp',
	fax='$inp_fax'
		where user_id=$inp_userid");
	echo '<script>window.location.href="admin.php?show=edit_user&id='.$inp_userid.'&msg=1";</script>';
	}
}

?>